package com.iplant.wms.serviceImpl.dao.hr;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.utils.annotation.dao.DBBaseDAO;
import com.iplant.base.utils.general.CalendarTool;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.basicenum.wms.WMSStockAlarmStatus;
import com.iplant.wms.service.po.hr.WMSStockAlarmItemHR;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@DBBaseDAO(WMSStockAlarmItemHR.class )
public class WMSStockAlarmItemHRDAO extends BaseDAO {

	private static WMSStockAlarmItemHRDAO Instance = null;
	private static Logger logger = LoggerFactory.getLogger(WMSStockAlarmItemHRDAO.class);

	private WMSStockAlarmItemHRDAO() {
		super("");
		this.Init();

	}

	public static WMSStockAlarmItemHRDAO getInstance() {
		if (Instance == null)
			Instance = new WMSStockAlarmItemHRDAO();
		return Instance;
	}

	/**
	 * 将今日之前的所有没关闭的全部关闭
	 * @param wLoginUser
	 * @param wErrorCode
	 */
	public void WMS_UpdateStockAlarmHRStatusCancel(BMSEmployee wLoginUser,
												   OutResult<Integer> wErrorCode){
		wErrorCode.set(0);
		try {

			String wSQLText = StringUtils.Format("update {0} t set t.Status=:wStatus " +
							" where  t.ID>0 and t.Status = :wStatusActive " +
							" and t.AlarmDate< :wNowDate ",
					this.getTableName());

			Map<String,Object> wParams=new HashMap<>();
			wParams.put("wStatus", WMSStockAlarmStatus.Cancel.getValue());
			wParams.put("wStatusActive", WMSStockAlarmStatus.Alarm.getValue());
			wParams.put("wNowDate", CalendarTool.getDate());
			this.Update(wSQLText,wParams);

		} catch (Exception e) {
			wErrorCode.Result = ExceptionTypes.DBSQL.getValue();
			log.error("WMS_UpdateStockAlarmHRStatusCancel", e);
		}
	}


}
